# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/21'
__author__ = 'Just'
__filename__ = 'banner'
"""
from flask import jsonify
from app.libs.error_code import Success, DeleteSuccess, NotFoundException
from app.libs.redprint import Redprint
from app.libs.token_auth import auth
from app.model.banner import Banner
from app.model.banner_item import BannerItem
from app.model.base import db
from app.validators.form import BannerChangeForm, BannerDataForm, BannerDataDeleteForm
from app.viewmodel.banner import BannerCollection


api = Redprint('banner')


@api.route('', methods=['GET'])
def banners():
    """获取banner 列表"""
    banner_list = Banner.banners_for_user()
    if not banner_list:
        raise NotFoundException(msg='暂无banner数据', error_code=2010)
    items = [x.items.all() for x in banner_list]
    collection = BannerCollection()
    collection.fill(list(zip(banner_list, items)))
    return jsonify(collection)
